package com.dxysun.mine;

import com.alibaba.fastjson.JSONObject;
import com.dxysun.ApiServiceManager;
import com.dxysun.api.MyApi;
import com.dxysun.impl.MyApiImpl;
import com.dxysun.mine.dto.Goods;
import com.google.common.collect.Sets;
import com.google.common.primitives.Ints;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;

public class MineMain
{



    public static void main(String[] args)
    {

        Map<String, MyApi>  myApiMap = ApiServiceManager.getInstance().getMap();

        System.out.println(MyApiImpl.class.getName());
        System.out.println(myApiMap.size());
        myApiMap.forEach((k , v) -> {
            System.out.println(k + ":" + v.getClass().getName());
            System.out.println(v.getName(k + " say good"));
        });

    }



    public static void test1()
    {
        List<Goods> goodsList = new ArrayList<>();

        Goods goods1 = new Goods();
        goods1.setName("a");
        goods1.setType("3");
        goods1.setPrice(15.00);
        goodsList.add(goods1);

        Goods goods2 = new Goods();
        goods2.setName("b");
        goods2.setType("1");
        goods2.setPrice(8.00);
        goodsList.add(goods2);

        Goods goods3 = new Goods();
        goods3.setName("a");
        goods3.setType("3");
        goods3.setPrice(10.00);
        goodsList.add(goods3);

        System.out.println(JSONObject.toJSONString(goodsList));

        goodsList.sort((o1, o2) -> {
            if (o1.getName().compareTo(o2.getName()) > 0)
            {
                return 1;
            }
            else if(o1.getName().compareTo(o2.getName()) == 0)
            {
                if(o1.getType().compareTo(o2.getType()) > 0)
                {
                    return 1;
                }
                else if(o1.getType().compareTo(o2.getType()) == 0)
                {
                    return o1.getPrice() - o2.getPrice() > 0 ? 1 : -1;
                }
                else
                {
                    return -1;
                }
            }
            else
            {
                return -1;
            }
        });

        System.out.println(JSONObject.toJSONString(goodsList));

        List<Integer> integerList = new ArrayList<>();

        integerList.add(4);
        integerList.add(5);
        integerList.add(3);
        integerList.add(1);
        integerList.add(2);
        System.out.println(JSONObject.toJSONString(integerList));

        integerList.sort((o1,o2) -> {
            if(o1 > o2)
            {
                return 1;
            }
            else if (o1.equals(o2))
            {
                return 0;
            }
            else
            {
                return -1;
            }
        });

        System.out.println(JSONObject.toJSONString(integerList));
    }
}
